package ru.ksu.ktk.diploma.sdi.mapping.thesauri;

/**
 * Thesauri descriptor
 * 
 * @author coldflame
 */
public class ThesauriDescriptor {
    /**
     * id
     */
    private String id;
    /**
     * absolute frequency [0..+infinity]
     */
    private int frequency;

    public ThesauriDescriptor(String text) {
        this.id = text;
    }

    public String getId() {
        return id;
    }

    public void setId(String text) {
        this.id = text;
    }

    public int getFrequency() {
        return frequency;
    }

    public void setFrequency(int frequency) {
        this.frequency = frequency;
    }

    /**
     * increase frequency in unit (+1)
     */
    public void increaseFrequency() {
        this.frequency++;
    }

    /**
     * returns string representation of thesauri descriptor in format "text: frequency", f.e. "word: 5"
     */
    @Override
    public String toString() {
        return String.format("%s: %d", id, frequency);
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) return true;
        if (!(o instanceof ThesauriDescriptor)) return false;
        ThesauriDescriptor td = (ThesauriDescriptor) o;
        return (id == null ? td.getId() == null : id.equals(td.getId()));
    }

    @Override
    public int hashCode() {
        int result = 17;
        if (id != null){
            result = 31 * result + id.hashCode();
        }
        return result;
    }

}
